/**   
 * @Title: DaletouChooseAct.java 
 * @Package com.esun.rabbit2.viewer.mainact.lotteryhallact.daletouagp 
 * @Description: (大乐透选号activity) 
 * @author: City Jiangsy@500wan.com   
 * @date: 2011-7-5 下午02:00:25  
 * Copyright: (C) 2011 Shenzhen E-sun Sky Net Technology Co.,ltd.
 */
package com.esun.rabbit2.viewer.mainact.lotteryhallact.daletouagp;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;

import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener;
import android.content.Intent;
import android.graphics.Rect;
import android.hardware.SensorListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.AnimationUtils;
import android.view.animation.AnticipateOvershootInterpolator;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.esun.config.Config;
import com.esun.config.Key;
import com.esun.config.Language;
import com.esun.model.CurrentLotteryNumInfo;
import com.esun.model.DaletouInfo;
import com.esun.model.UserInfo;
import com.esun.network.ConnectionChangeReceiver;
import com.esun.network.communicater.UserCommunicater;
import com.esun.rabbit2.communicaters.CurrentLotteryNumCommunicater;
import com.esun.rabbit2.communicaters.DaletouTraceExpectCommunicater;
import com.esun.rabbit2.communicaters.daletou.DaletouNormalBuyCommunicater;
import com.esun.rabbit2.viewer.LoginAct;
import com.esun.rabbit2.viewer.RegistAct;
import com.esun.rabbit2.viewer.WebViewActivity;
import com.esun.rabbit2.viewer.mainact.OptionAct;
import com.esun.rabbit2.viewer.mainact.lotteryhallact.BallMenuBuilder;
import com.esun.rabbit2.viewer.mainact.lotteryhallact.DaletouAgp;
import com.esun.rabbit2.viewer.mainact.mylotteryact.recharg.RechargeMenuPage;
import com.esun.ui.R;
import com.esun.util.LoginTimeControl;
import com.esun.util.LotteryUtils;
import com.esun.util.Vibrate;
import com.esun.util.ViewerUtil;
import com.esun.util.log.EDebug;
import com.esun.util.wheel.widget.NumericWheelAdapter;
import com.esun.util.wheel.widget.OnWheelChangedListener;
import com.esun.util.wheel.widget.OnWheelScrollListener;
import com.esun.util.wheel.widget.WheelView;

/**
 * @ClassName: DaletouChooseAct
 * @Description: (大乐透选号activity)
 * @author: City Jiangsy@500wan.com
 * @date: 2011-7-5 下午02:00:25
 * 
 */
@SuppressWarnings("deprecation")
public class DaletouChooseAct extends Activity implements OnClickListener, SensorListener {

	private View chooseView; // 选球界面
	private View lotteryListView; // 列表界面
	private BallMenuBuilder ballMenuBuilderBlue; // 蓝球菜单
	private BallMenuBuilder ballMenuBuilderRed; // 红球菜单
	private LinearLayout linearBallMenuBlue; // 承载菜单的layout
	private LinearLayout linearBallMenuRed; // 承载菜单的layout
	private TextView tvBetNum; // 注数
	private TextView tvMoney; // 金额

	private Button btnCancel; // 放弃
	private Button btnClean; // 清空
	private Button btnRandom; // 随机
	private Button btnSubmit; // 确定选号
	private Button btnRedRandom; // 红球随机
	private Button btnBlueRandom; // 蓝球随机
	private Button btnListClean;
	private Button btnListCancel; // 返回选球
	private Button btnListAdd; // 添加单注随机投注
	private Button btnListHemai; // 发起合买
	private Button btnListSubmit; // 确认投注
	private TextView tvListBetCount; // 列表注数
	private TextView tvListMoney; // 列表金额

	private int betCountAll = 0; // 总注数
	private int moneyAll = 0; // 总金额
	public static int showType = 0;
	private LinearLayout linearListSpace;
	private View.OnClickListener listenerListItem;

	public static boolean isChooseView = true;
	private int listTagShow = -1;

	private int pageTag;
	/************************* 1.6.0 kael添加 **********************/
	/** 记录机选注数 */
	private int randomZhuShu = 0;
	/** 记录机选红球个数 */
	private int randomRedBallNum = 0;
	/** 记录机选篮球个数 */
	private int randomBlueBallNum = 0;
	/** 上期中奖号码按钮 */
	private Button btnLastLotteryNum;
	/** 显示中奖号码TextView所在的LinearLayout */
	private LinearLayout llLastLotteryNum;
	/** 显示上期中奖号码红色号码的TextView */
	private TextView tvLastLotteryNumRed;
	/** 显示上期中奖号码蓝色号码的TextView */
	private TextView tvLastLotteryNumBlue;
	/** 上期中奖号码红球 */
	private String redcode;
	/** 上期中奖号码篮球 */
	private String bluecode;
	/** 承载加载上期中奖号码ProgressBar的LinearLayout */
	private LinearLayout llLastLotteryNumProgress;
	/** 显示“加载失败”的LinearLayout */
	private LinearLayout llLastLotteryNumShibai;
	/** 机选红球个数选择菜单按钮 */
	private LinearLayout btnRedRandomNum;
	/** 显示机选红球个数的TextView */
	private TextView tvRedRandomNum;
	/** 机选蓝球个数选择菜单按钮 */
	private LinearLayout btnBlueRandomNum;
	/** 显示机选蓝球个数的TextView */
	private TextView tvBlueRandomNum;
	/** 显示机选红球个数按钮上的箭头 */
	private ImageView ivRedRandomNum;
	/** 显示机选蓝球个数按钮上的箭头 */
	private ImageView ivBlueRandomNum;
	/** 标记点击的是选择机选篮球个数的按钮 */
	private static final int RANDOMBLUEBALLTAG = 1;
	/** 标记点击的是选择机选红球个数的按钮 */
	private static final int RANDOMREDBALLTAG = 2;
	/** 判断点击的是选择哪种球机选个数的按钮，以便randomRedBallNum、randomBlueBallNum的赋值 */
	private int randomNumTag;
	/** 机选个数dialog适配器 */
	private ShowRandomNumDialogAdapter showRandomNumDialogAdapter;
	/** 机选红球个数选择Dialog */
	private Dialog dialogRed;
	/** 机选篮球个数选择Dialog */
	private Dialog dialogBlue;
	/** 判断是否点击dialog内部button导致dialog消失的还是按返回键dialog才消失的 */
	private boolean isClicked = false;
	/** 存放机选蓝球个数的ArrayList */
	private ArrayList<Hashtable<String, Object>> arrBlueBallNum;
	/** 存放机选红球个数的ArrayList */
	private ArrayList<Hashtable<String, Object>> arrRedBallNum;

	/** 存放倍投倍数的ArrayList 1~50 */
	private ArrayList<String> beishuNum;
	/** 存放追号期数的ArrayList 1~30 */
	private ArrayList<String> zhuihaoNum;
	/** 用户合同代购协议 */
	private LinearLayout btnUserAgreement;
	/** 设置倍投追号 */
	private LinearLayout llSetBeitouZhuihao;
	/** 选号列表显示倍数的TextView */
	private TextView tvListBeiShu;
	/** 选号列表显示追号期数的TextView */
	private TextView tvListZhuiHao;
	/** 显示追加投注字样 */
	private TextView tvListZhuijiaTouzhu;
	/** 显示倍投追号的Dialog */
	private Dialog beiTouZhuihaoDialog;
	/** 倍投滚轮 */
	private WheelView beishuWheel;
	/** 追号滚轮 */
	private WheelView zhuihaoWheel;
	/** 判断滚轮是否在滚动 */
	private boolean wheelScrolled = false;
	/** 滚轮当前位置的倍投 */
	private String beishuCurrent = Config.NUM1;
	/** 滚轮当前位置的追号 */
	private String zhuihaoCurrent = Config.NUM1;
	/** 点击确定按钮后的倍投 */
	private String beishuEnd = Config.NUM1;
	/** 点击确定按钮后的追号 */
	private String zhuihaoEnd = Config.NUM1;
	/** 设置倍投追号Dialog上完成按钮 */
	private Button btnDialogFinish;
	/** 设置倍投追号Dialog上取消按钮 */
	private Button btnDialogCancel;
	/** 中奖后停止追号的CheckBox */
	private CheckBox cbDialogStop;
	/** 确认提交订单的Dialog */
	private Dialog submitOrderDialog;
	/** 确认提交订单按钮 */
	private Button btnSubmitOrder;
	/** 取消提交订单按钮 */
	private Button btnCancelOrder;
	/** 复式代购购买进度 */
	private ProgressDialog progressdialogNormalbuy;
	/** 复式代购Handler */
	public static Handler handlerNormalBuy;
	/** 标识（用于随机个数Dialog适配）红球 */
	private static final int REDBALL = 0;
	/** 标识（用于随机个数Dialog适配）蓝球 */
	private static final int BLUEBALL = 1;
	/** 标识位,购买成功 */
	private static final int NORMALBUY_SUCCEED = 1001;
	/** 标识位,购买失败 */
	private static final int NORMALBUY_FAIL = 1002;
	/** 标识位,获取余额成功 */
	private static final int GETBALANCE_SUCCEED = 1003;
	/** 标识位,获取余额失败 */
	private static final int GETBALANCE_FAIL = 1004;
	/** 获取期号成功 */
	private static final int GET_EXPECT_LIST_SUCCEED = 10005;
	/** 获取期号失败 */
	private static final int GET_EXPECT_LIST_FAILED = 10006;
	/** 获取上期中奖号码成功 */
	private static final int GET_LOTTERY_NUM_SUCCEED = 10007;
	/** 获取上期中奖号码失败 */
	private static final int GET_LOTTERY_NUM_FAILED = 10008;
	/** 购彩接口 */
	private DaletouNormalBuyCommunicater daletouNormalBuyCommunicater;
	private DaletouTraceExpectCommunicater expectCommuniacter;
	UserCommunicater userCommunicater;
	/** 获取当期中奖号码接口 */
	private CurrentLotteryNumCommunicater currentLotteryNumCommunicater;
	/** 判断是否中奖后停止追号 */
	private boolean isStopZhuihao = false;
	/** 判断是否追加投注 */
	private boolean isZhuiJiaTouZhu = false;
	private boolean isGetBalance;
	private Dialog dialogBuySucceed;
	private Dialog dialogBalanceNotEnough;
	private View.OnClickListener moneyNotEnoughListener;

	private LinearLayout linear_zhuijiatouzhu;
	private CheckBox cbDialog_zhuijiatouzhu;
	/** 每份金额 */
	private int eachMoney;
	/** 最新开奖号码信息 */
	private CurrentLotteryNumInfo lotteryNumInfo;
	/** 标志位 当选择随机个数Dialog正在显示的时候不支持晃动选号 */
	private boolean isRandomDialogNotShow = true;
	public static final int DO_REFRESH = 10009;
	/*******************************************************/

	/************************* 晃动相关 **********************/
	private SensorManager sensorMgr;
	private long lastUpdate = -1;
	private float x, y, z;
	private float last_x, last_y, last_z;
	private static final int SHAKE_THRESHOLD = 800;

	/*******************************************************/

	// private boolean isRebuy;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		chooseView = this.getLayoutInflater().inflate(R.layout.daletou_choose_act, null);

		lotteryListView = this.getLayoutInflater().inflate(R.layout.daletou_choose_act_list, null);
		pageTag = 1;
		initDate();
		initHandler();
		initChooseViewUI();
		initLotteryListViewUI();
		determineSetContentView();
	}

	/** 判定显示选球界面还是列表界面,当菜单中有内容时直接显示列表,没有则进入选球界面 */
	private void determineSetContentView() {

		if (DaletouInfo.getDaletouInfo().getLotteryList().size() == 0) {
			setContentView(chooseView);
			btnCancel.setVisibility(View.GONE);
			isChooseView = true;
			Message msg = DaletouAgp.handlerDaletouAgp.obtainMessage(DaletouAgp.IN_CHOOSE_VIEW, null);
			DaletouAgp.handlerDaletouAgp.sendMessage(msg);
		} else {
			isChooseView = false;
			setContentView(lotteryListView);
			updataListView();
			Message msg = DaletouAgp.handlerDaletouAgp.obtainMessage(DaletouAgp.IN_LIST_VIEW, null);
			DaletouAgp.handlerDaletouAgp.sendMessage(msg);
		}
	}

	private void initLotteryListViewUI() {

		btnListClean = (Button) lotteryListView.findViewById(R.id.daletouchooselistact_btn_cleanlist);
		btnListClean.setOnClickListener(this);
		btnListCancel = (Button) lotteryListView.findViewById(R.id.daletouchooselistact_btn_cancel);
		btnListCancel.setOnClickListener(this);

		btnListAdd = (Button) lotteryListView.findViewById(R.id.daletouchooselistact_btn_add);
		btnListAdd.setOnClickListener(this);

		btnListHemai = (Button) lotteryListView.findViewById(R.id.daletouchooselistact_btn_hemai);
		btnListHemai.setOnClickListener(this);

		btnListSubmit = (Button) lotteryListView.findViewById(R.id.daletouchooselistact_btn_submit);
		btnListSubmit.setOnClickListener(this);

		tvListBetCount = (TextView) lotteryListView.findViewById(R.id.daletouchooselistact_tv_zhushu);

		tvListMoney = (TextView) lotteryListView.findViewById(R.id.daletouchooselistact_tv_qianshu);

		tvListZhuijiaTouzhu = (TextView) lotteryListView.findViewById(R.id.daletouchooselistact_tv_zhuijiatouzhu);

		linearListSpace = (LinearLayout) lotteryListView.findViewById(R.id.daletouchooseactlist_linear_listSpace);

		listenerListItem = new OnClickListener() {

			@Override
			public void onClick(View v) {

				listTagShow = Integer.parseInt(String.valueOf(v.getTag()));
				setChooseview();
			}
		};
		btnUserAgreement = (LinearLayout) lotteryListView.findViewById(R.id.daletouchooselistact_btn_xieyi);
		btnUserAgreement.setOnClickListener(this);
		llSetBeitouZhuihao = (LinearLayout) lotteryListView.findViewById(R.id.daletouchooselistact_btn_setbeitou);
		llSetBeitouZhuihao.setOnClickListener(this);
		tvListBeiShu = (TextView) lotteryListView.findViewById(R.id.daletouchooselistact_tv_beishu);
		tvListZhuiHao = (TextView) lotteryListView.findViewById(R.id.daletouchooselistact_tv_qishu);
		progressdialogNormalbuy = ViewerUtil.showProgressDialog(this, Language.POPLOTTERYTIP_BUYING);
	}

	private void initChooseViewUI() {

		tvBetNum = (TextView) chooseView.findViewById(R.id.daletouchooseact_tv_betNum);
		tvMoney = (TextView) chooseView.findViewById(R.id.daletouchooseact_tv_money);
		ivRedRandomNum = (ImageView) chooseView.findViewById(R.id.daletouchooseact_iv_redjiantou);
		ivRedRandomNum.setImageResource(R.drawable.icon_default_random_red_arrows_19x11);

		ivBlueRandomNum = (ImageView) chooseView.findViewById(R.id.daletouchooseact_iv_bluejiantou);
		ivBlueRandomNum.setImageResource(R.drawable.icon_default_random_blue_arrows_19x11);

		ballMenuBuilderRed = new BallMenuBuilder(this, 35, 18, 0, tvBetNum, tvMoney, Config.DALETOU);
		ballMenuBuilderBlue = new BallMenuBuilder(this, 12, 13, 1, tvBetNum, tvMoney, Config.DALETOU);

		linearBallMenuBlue = (LinearLayout) chooseView.findViewById(R.id.daletouchooseact_Linear_ballMenuBlue);
		linearBallMenuBlue.addView(ballMenuBuilderBlue.setKeyBoad());

		linearBallMenuRed = (LinearLayout) chooseView.findViewById(R.id.daletouchooseact_Linear_ballMenuRed);
		linearBallMenuRed.addView(ballMenuBuilderRed.setKeyBoad());

		btnCancel = (Button) chooseView.findViewById(R.id.daletouchooseact_btn_cancel);
		btnCancel.setOnClickListener(this);

		btnClean = (Button) chooseView.findViewById(R.id.daletouchooseact_btn_clean);
		btnClean.setOnClickListener(this);

		btnRandom = (Button) chooseView.findViewById(R.id.daletouchooseact_btn_random);
		btnRandom.setOnClickListener(this);

		btnSubmit = (Button) chooseView.findViewById(R.id.daletouchooseact_btn_submit);
		btnSubmit.setOnClickListener(this);

		btnRedRandom = (Button) chooseView.findViewById(R.id.daletouchooseact_btn_redRandom);
		btnRedRandom.setOnClickListener(this);

		btnBlueRandom = (Button) chooseView.findViewById(R.id.daletouchooseact_btn_blueRandom);
		btnBlueRandom.setOnClickListener(this);

		btnLastLotteryNum = (Button) chooseView.findViewById(R.id.daletouchooseact_btn_lottery_num);
		btnLastLotteryNum.setOnClickListener(this);

		btnBlueRandomNum = (LinearLayout) chooseView.findViewById(R.id.daletouchooseact_btn_blueRandomnum);
		btnBlueRandomNum.setOnClickListener(this);
		tvBlueRandomNum = (TextView) chooseView.findViewById(R.id.daletouchooseact_tv_blueRandomnum);

		btnRedRandomNum = (LinearLayout) chooseView.findViewById(R.id.daletouchooseact_btn_redRandomnum);
		btnRedRandomNum.setOnClickListener(this);
		tvRedRandomNum = (TextView) chooseView.findViewById(R.id.daletouchooseact_tv_redRandomnum);

		llLastLotteryNum = (LinearLayout) chooseView.findViewById(R.id.daletouchooseact_ll_lottery_num);
		llLastLotteryNum.setOnClickListener(this);
		llLastLotteryNumProgress = (LinearLayout) chooseView.findViewById(R.id.daletouchooseact_ll_lottery_num_progress);

		llLastLotteryNumShibai = (LinearLayout) chooseView.findViewById(R.id.daletouchooseact_ll_lottery_num_shibai);
		llLastLotteryNumShibai.setOnClickListener(this);

		tvLastLotteryNumRed = (TextView) chooseView.findViewById(R.id.daletouchooseact_tv_lottery_numred);
		tvLastLotteryNumBlue = (TextView) chooseView.findViewById(R.id.daletouchooseact_tv_lottery_numblue);
	}

	@Override
	public void onClick(View v) {

		switch (v.getId()) {
		case R.id.daletouchooseact_btn_cancel:
			isChooseView = false;

			/** title change 2011-7-27 city */
			Message msg = DaletouAgp.handlerDaletouAgp.obtainMessage(DaletouAgp.IN_LIST_VIEW, null);
			DaletouAgp.handlerDaletouAgp.sendMessage(msg);

			listTagShow = -1;
			this.setContentView(lotteryListView);
			ballMenuBuilderBlue.cleanKeyBoad();
			ballMenuBuilderRed.cleanKeyBoad();

			break;

		case R.id.daletouchooseact_btn_clean:

			ballMenuBuilderBlue.cleanKeyBoad();
			ballMenuBuilderRed.cleanKeyBoad();
			break;

		case R.id.daletouchooseact_btn_random:
			singleRandom();
			break;

		case R.id.daletouchooseact_btn_submit:
			int money = Integer.valueOf(tvMoney.getText().toString().replace(Config.ONESPACE, Config.NULLMARK));

			if (money > Config.MAXIMUM_BET_DALETOU) {
				ViewerUtil.showTipDialog(DaletouChooseAct.this, getResources().getString(R.string.maximum_bet_dlt), false);
			} else {
				setListView();
			}
			break;

		case R.id.daletouchooseact_btn_redRandom:
			redBallRandom();
			break;

		case R.id.daletouchooseact_btn_blueRandom:
			blueBallRandom();
			break;

		case R.id.daletouchooselistact_btn_cancel:
			setChooseview();
			break;

		case R.id.daletouchooselistact_btn_cleanlist:
			DaletouInfo.getDaletouInfo().getLotteryList().clear();
			beishuEnd = Config.NUM1;
			zhuihaoEnd = Config.NUM1;
			isZhuiJiaTouZhu = false;
			tvListBeiShu.setText(beishuEnd);
			tvListZhuiHao.setText(zhuihaoEnd);
			tvListZhuijiaTouzhu.setVisibility(View.GONE);
			updataListViewWithMsg();

			break;

		case R.id.daletouchooselistact_btn_add:
			randomLotQuickAdd();
			break;

		case R.id.daletouchooselistact_btn_submit:
			showDaletouNormalBuy();
			break;

		case R.id.daletouchooselistact_btn_hemai:
			showdaletouHemai();
			break;

		case R.id.buylistlinearitem_btn_delete:
			View viewListItem = (View) v.getParent().getParent().getParent();
			RelativeLayout linearItem = (RelativeLayout) viewListItem.findViewById(R.id.buylistlinearitem_linear_item);
			int tag = (Integer) linearItem.getTag();
			EDebug.o(DaletouChooseAct.this, "buylistlinearitem_btn_delete is click & the tag is " + String.valueOf(viewListItem.getTag()));
			deleteListItem(viewListItem, tag);
			break;

		case R.id.daletouchooseact_btn_blueRandomnum:// 点击机选蓝球个数按钮
			randomNumTag = RANDOMBLUEBALLTAG;
			EDebug.o("blueRandom", "blueRandom====================================");
			showRandomNumDialogAdapter = new ShowRandomNumDialogAdapter(DaletouChooseAct.this, arrBlueBallNum, BLUEBALL);
			if (dialogBlue == null) {
				dialogBlue = ViewerUtil.showRandomNumDialog(DaletouChooseAct.this, showRandomNumDialogAdapter);
			}
			ivBlueRandomNum.setImageResource(R.drawable.icon_up_random_blue_arrows_19x11);
			dialogBlue.setOnDismissListener(new OnDismissListener() {
				@Override
				public void onDismiss(DialogInterface dialog) {
					if (isClicked) {// 是点击Dialog中的按钮导致Dialog消失的则显示个数并执行机选
						tvBlueRandomNum.setText(Integer.toString(randomBlueBallNum) + Language.MSG_GE);
						blueBallRandom();
					} else {// 按返回键导致Dialog消失的则只显示个数不执行机选
						if (randomBlueBallNum == 0) {
							tvBlueRandomNum.setText(2 + Language.MSG_GE);
						}
					}
					ivBlueRandomNum.setImageResource(R.drawable.icon_default_random_blue_arrows_19x11);
					isClicked = false;
					isRandomDialogNotShow = true;
				}
			});
			int[] locationBlue = new int[2];
			linearBallMenuBlue.getLocationOnScreen(locationBlue);

			int yBlue = locationBlue[1];
			int topHeightBlue = getTopHeight();
			EDebug.o("yRed:" + yBlue + "topHeight" + topHeightBlue);
			yBlue = yBlue - topHeightBlue;
			EDebug.o("yRed:" + yBlue);
			Window blueDialogWindow = dialogBlue.getWindow();
			blueDialogWindow.setGravity(Gravity.RIGHT | Gravity.TOP);
			WindowManager.LayoutParams bluelp = blueDialogWindow.getAttributes();
			bluelp.x = 8;
			bluelp.y = yBlue;
			dialogBlue.onWindowAttributesChanged(bluelp);
			dialogBlue.show();
			isRandomDialogNotShow = false;
			break;
		case R.id.daletouchooseact_btn_redRandomnum:// 点击机选红球个数按钮
			randomNumTag = RANDOMREDBALLTAG;
			EDebug.o("redRandom", "redRandom====================================");
			showRandomNumDialogAdapter = new ShowRandomNumDialogAdapter(DaletouChooseAct.this, arrRedBallNum, REDBALL);
			if (dialogRed == null) {
				dialogRed = ViewerUtil.showRandomNumDialog(DaletouChooseAct.this, showRandomNumDialogAdapter);
			}
			ivRedRandomNum.setImageResource(R.drawable.icon_up_random_red_arrows_19x11);
			dialogRed.setOnDismissListener(new OnDismissListener() {
				@Override
				public void onDismiss(DialogInterface dialog) {
					if (isClicked) {// 是点击Dialog中的按钮导致Dialog消失的则显示个数并执行机选
						tvRedRandomNum.setText(Integer.toString(randomRedBallNum) + Language.MSG_GE);
						redBallRandom();
					} else {// 按返回键导致Dialog消失的则只显示个数不执行机选
						if (randomRedBallNum == 0) {
							tvRedRandomNum.setText(5 + Language.MSG_GE);
						}
					}
					ivRedRandomNum.setImageResource(R.drawable.icon_default_random_red_arrows_19x11);
					isClicked = false;
					isRandomDialogNotShow = true;
				}
			});
			int[] locationRed = new int[2];
			linearBallMenuRed.getLocationOnScreen(locationRed);
			int yRed = locationRed[1];
			int topHeightRed = getTopHeight();
			EDebug.o("yRed:" + yRed + "topHeight" + topHeightRed);
			yRed = yRed - topHeightRed;
			EDebug.o("yRed:" + yRed);
			Window redDialogWindow = dialogRed.getWindow();
			redDialogWindow.setGravity(Gravity.RIGHT | Gravity.TOP);
			WindowManager.LayoutParams redlp = redDialogWindow.getAttributes();
			redlp.x = 8;
			redlp.y = yRed;
			dialogRed.onWindowAttributesChanged(redlp);
			dialogRed.show();
			isRandomDialogNotShow = false;
			break;

		case R.id.daletouchooseact_btn_lottery_num:
			btnLastLotteryNum.setVisibility(View.GONE);
			if (redcode != null && !redcode.equals(Config.NULLMARK) && bluecode != null && !bluecode.equals(Config.NULLMARK)) {
				llLastLotteryNum.setVisibility(View.VISIBLE);
				tvLastLotteryNumRed.setText(redcode);
				tvLastLotteryNumBlue.setText(bluecode);
			} else {
				llLastLotteryNumProgress.setVisibility(View.VISIBLE);
				threadGetCurrentLotteryNum(Config.DALETOU);
			}
			break;

		case R.id.daletouchooseact_ll_lottery_num:
			btnLastLotteryNum.setVisibility(View.VISIBLE);
			llLastLotteryNum.setVisibility(View.GONE);
			break;

		case R.id.daletouchooseact_ll_lottery_num_shibai:
			btnLastLotteryNum.setVisibility(View.VISIBLE);
			llLastLotteryNumShibai.setVisibility(View.GONE);
			break;

		case R.id.daletouchooselistact_btn_xieyi:
			Intent intent = new Intent();
			intent.putExtra(Key.KEY_URL, Config.USER_DAIGOUXIEYI_WEBVIEW_URL);
			intent.putExtra(Key.KEY_TITLE, "用户合同代购协议");
			intent.setClass(this, WebViewActivity.class);
			this.startActivity(intent);
			break;

		case R.id.daletouchooselistact_btn_setbeitou:
			showBeitouZhuihaoDialog();
			break;

		case R.id.dialog_beitou_zhuihao_btn_submit:
			beishuEnd = beishuCurrent;
			zhuihaoEnd = zhuihaoCurrent;
			int moneyEnd = Integer.parseInt(beishuEnd) * moneyAll;
			beiTouZhuihaoDialog.dismiss();
			tvListBeiShu.setText(beishuEnd);
			tvListZhuiHao.setText(zhuihaoEnd);
			tvListMoney.setText(Integer.toString(moneyEnd));
			if (isZhuiJiaTouZhu) {
				tvListZhuijiaTouzhu.setVisibility(View.VISIBLE);
			} else {
				tvListZhuijiaTouzhu.setVisibility(View.GONE);
			}
			break;

		case R.id.dialog_beitou_zhuihao_btn_cancle:
			beiTouZhuihaoDialog.dismiss();
			break;

		case R.id.dialogquit_btn_submit:
			submitOrderDialog.dismiss();
			progressdialogNormalbuy.show();
			String termNum = DaletouInfo.getDaletouInfo().getTermNum();
			threadGetExpectList(termNum, zhuihaoEnd);
			break;

		case R.id.dialogquit_btn_cancel:
			submitOrderDialog.dismiss();
			break;
		default:
			break;
		}

	}

	private void deleteListItem(View view, int tag) {

		linearListSpace.removeView(view);

		EDebug.o(DaletouChooseAct.this, "betCountAll is " + betCountAll + " & the bet is " + (Integer) DaletouInfo.getDaletouInfo().getLotteryList().get(tag).get("bet_count"));

		DaletouInfo.getDaletouInfo().getLotteryList().remove(tag);
		updataListViewWithMsg();

	}

	/**
	 * @Title: showDaletouNormalBuy
	 * @Description: 购买
	 * @param: 设定文件
	 * @return: void 返回类型
	 * @throws
	 */
	private void showDaletouNormalBuy() {
		pageTag = 1;
		if (DaletouInfo.getDaletouInfo().getLotteryList().size() == 0) {
			ViewerUtil.showTipDialog(DaletouChooseAct.this, Language.STR_ZUISHAOXUANZEYIZHUHAOMA, false);
		} else if (UserInfo.getUserInfo().getUserSession().length() < 3) {
			Intent intentToLogin = new Intent();
			intentToLogin.setClass(DaletouChooseAct.this, LoginAct.class);
			startActivity(intentToLogin);
		} else if (Double.parseDouble(UserInfo.getUserInfo().getUserBalance()) == 0) {
			showZeroMoneyDialog(1);
		} else if (!isGetBalance) {
			ViewerUtil.showTipDialog(DaletouChooseAct.this, Language.MSG_WAIT_GET_YUE, false);
		} else if (UserInfo.getUserInfo().getUserSession().length() < 3) {
			Intent intent = new Intent();
			intent.setClass(DaletouChooseAct.this, LoginAct.class);
			startActivity(intent);
		} else {
			LoginTimeControl test = new LoginTimeControl();
			if (test.isNeedInputPwd()) {
				test.showInputPasswordDialog(DaletouChooseAct.this);
			} else {
				if (submitOrderDialog == null) {
					showSubmitOrderDialog(Language.MSG_ASK_SUBMIT_ORDER, Language.MSG_SUBMIT);
				}
				submitOrderDialog.show();
			}
		}

	}

	private void singleRandom() {

		isChooseView = false;
		OnClickListener randomSingleListener = new View.OnClickListener() {

			@Override
			public void onClick(View v) {

				DaletouChooseAct.this.setContentView(lotteryListView);
				int randomCount = ViewerUtil.getRandomCount();
				for (int i = 0; i < randomCount; i++) {
					addSingleRandomToList();
				}
				listTagShow = -1;
				ViewerUtil.dismissRandomDialog();
				randomZhuShu = randomCount;
				updataListViewWithMsg();
				isChooseView = false;
				ViewerUtil.isInChooseView = true;
			}
		};
		ViewerUtil.showRandomDialog(DaletouChooseAct.this, Language.MSG_SELECT_SUIJI_ZHUSHU, 1, 10, 10, randomZhuShu, randomSingleListener);

	}

	private void showdaletouHemai() {

		pageTag = 2;
		if (DaletouInfo.getDaletouInfo().getLotteryList().size() == 0) {
			ViewerUtil.showTipDialog(DaletouChooseAct.this, Language.STR_ZUISHAOXUANZEYIZHUHAOMA, false);
		} else if (UserInfo.getUserInfo().getUserSession().length() < 3) {
			Intent intentToLogin = new Intent();
			intentToLogin.setClass(DaletouChooseAct.this, LoginAct.class);
			startActivity(intentToLogin);
		}
		// else if (Double.parseDouble(UserInfo.getUserInfo().getUserBalance())
		// == 0 && (!ViewerUtil.isShowRegist)) {
		// showZeroMoneyDialog(2);
		// }
		else {
			// 合买页面,走你
			Intent intentToHemai = new Intent();
			intentToHemai.setClass(DaletouChooseAct.this, DaletouChooseHemaiAct.class);
			startActivity(intentToHemai);
		}

	}

	/**
	 * @Title: blueBallRandom
	 * @Description: 随机蓝球处理
	 * @param: 设定文件
	 * @return: void 返回类型
	 * 
	 */
	private void blueBallRandom() {
		isChooseView = false;
		if (randomBlueBallNum == 0) {
			ballMenuBuilderBlue.setKeyBoadRandom(LotteryUtils.randomNum(2, 12));
		} else {
			ballMenuBuilderBlue.setKeyBoadRandom(LotteryUtils.randomNum(randomBlueBallNum, 12));
			isChooseView = true;
		}

	}

	/**
	 * @Title: redBallRandom
	 * @Description: 随机红球处理
	 * @param: 设定文件
	 * @return: void 返回类型
	 * @throws
	 */
	private void redBallRandom() {

		isChooseView = false;
		if (randomRedBallNum == 0) {
			ballMenuBuilderRed.setKeyBoadRandom(LotteryUtils.randomNum(5, 35));
		} else {
			ballMenuBuilderRed.setKeyBoadRandom(LotteryUtils.randomNum(randomRedBallNum, 35));
			isChooseView = true;
		}

	}

	// 选球界面确认选号
	private void setListView() {

		ViewerUtil.isShowRegist = false;
		if (DaletouInfo.getDaletouInfo().getBetCount() < 1) {
			ViewerUtil.showTipDialog(this, Language.MSG_ZUISHAOXUANZEWUER, false);
		} else if (listTagShow == -1) {
			HashMap<String, Object> lotteryListItem = new HashMap<String, Object>();
			lotteryListItem.put(Key.KEY_BLUE, ListToString(ballMenuBuilderBlue.getListResult()));
			lotteryListItem.put(Key.KEY_RED, ListToString(ballMenuBuilderRed.getListResult()));
			lotteryListItem.put(Key.KEY_BET_COUNT, DaletouInfo.getDaletouInfo().getBetCount());
			DaletouInfo.getDaletouInfo().getLotteryList().add(0, lotteryListItem);
			this.setContentView(lotteryListView);
			updataListViewWithMsg();
		} else {
			HashMap<String, Object> lotteryListItem = new HashMap<String, Object>();
			lotteryListItem.put(Key.KEY_BLUE, ListToString(ballMenuBuilderBlue.getListResult()));
			lotteryListItem.put(Key.KEY_RED, ListToString(ballMenuBuilderRed.getListResult()));
			lotteryListItem.put(Key.KEY_BET_COUNT, DaletouInfo.getDaletouInfo().getBetCount());
			DaletouInfo.getDaletouInfo().getLotteryList().set(listTagShow, lotteryListItem);
			this.setContentView(lotteryListView);
			updataListViewWithMsg();
			listTagShow = -1;
		}
	}

	private void updataListViewWithMsg() {

		EDebug.o(DaletouChooseAct.this, "updataListView");
		/** title change 2011-7-27 city */
		Message msg = DaletouAgp.handlerDaletouAgp.obtainMessage(DaletouAgp.IN_LIST_VIEW, null);
		EDebug.o(DaletouChooseAct.this, "mesage send");
		DaletouAgp.handlerDaletouAgp.sendMessage(msg);
		updataListView();
	}

	private void updataListView() {

		linearListSpace.removeAllViews();

		EDebug.o(DaletouChooseAct.this, "over");

		isChooseView = false;

		LayoutParams param = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
		for (int i = DaletouInfo.getDaletouInfo().getLotteryList().size() - 1; i > 0 - 1; i--) {
			View viewListItem = DaletouChooseAct.this.getLayoutInflater().inflate(R.layout.buylist_linear_item, null);
			int redLength = ((String) DaletouInfo.getDaletouInfo().getLotteryList().get(i).get(Key.KEY_RED)).length();
			int blueLength = ((String) DaletouInfo.getDaletouInfo().getLotteryList().get(i).get(Key.KEY_BLUE)).length();
			EDebug.o(DaletouChooseAct.this, "redLength--------------" + redLength);
			EDebug.o(DaletouChooseAct.this, "blueLength------------" + blueLength);
			EDebug.o(DaletouChooseAct.this, "the tag is " + String.valueOf(viewListItem.getTag()));

			TextView tvItemRed = (TextView) viewListItem.findViewById(R.id.buylistlinearitem_tv_red);
			tvItemRed.setText(strLengthOption((String) DaletouInfo.getDaletouInfo().getLotteryList().get(i).get(Key.KEY_RED), 17));

			TextView tvItemBlue = (TextView) viewListItem.findViewById(R.id.buylistlinearitem_tv_blue);
			tvItemBlue.setText(strLengthOption((String) DaletouInfo.getDaletouInfo().getLotteryList().get(i).get(Key.KEY_BLUE), 10));
			TextView tvValue = (TextView) viewListItem.findViewById(R.id.buylistlinearitem_tv_value);
			// tvValue.setText(strLengthOption(stringListItemValue(i), 7));
			tvValue.setText(stringListItemValue(i));
			TextView tvItemStyle = (TextView) viewListItem.findViewById(R.id.buylistlinearitem_tv_touzhustyle);
			if (redLength == 14 && blueLength == 5) {
				tvItemStyle.setText(Language.MSG_DANSHITOUZHU);
			} else {
				tvItemStyle.setText(Language.MSG_FUSHITOUZHU);
			}
			Button btnItemDelete = (Button) viewListItem.findViewById(R.id.buylistlinearitem_btn_delete);
			btnItemDelete.setOnClickListener(DaletouChooseAct.this);

			RelativeLayout linearItem = (RelativeLayout) viewListItem.findViewById(R.id.buylistlinearitem_linear_item);
			linearItem.setTag(i);
			linearItem.setOnClickListener(listenerListItem);

			linearListSpace.addView(viewListItem, param);
		}
		ballMenuBuilderBlue.cleanKeyBoad();
		ballMenuBuilderRed.cleanKeyBoad();

		betCountAll = 0;
		for (int i = 0; i < DaletouInfo.getDaletouInfo().getLotteryList().size(); i++) {
			betCountAll += (Integer) DaletouInfo.getDaletouInfo().getLotteryList().get(i).get(Key.KEY_BET_COUNT);
		}
		moneyAll = betCountAll * eachMoney;
		int money = moneyAll * Integer.parseInt(beishuEnd);
		tvListBetCount.setText(Integer.toString(betCountAll));
		tvListMoney.setText(Integer.toString(money));
	}

	// 返回选球界面
	private void setChooseview() {

		/** title change 2011-7-27 city */
		Message msg = DaletouAgp.handlerDaletouAgp.obtainMessage(DaletouAgp.IN_CHOOSE_VIEW, null);
		DaletouAgp.handlerDaletouAgp.sendMessage(msg);

		isChooseView = true;
		setContentView(chooseView);
		if (DaletouInfo.getDaletouInfo().getLotteryList().size() == 0) {
			btnCancel.setVisibility(View.GONE);
		} else if (listTagShow != -1) {
			btnCancel.setVisibility(View.VISIBLE);
			ballMenuBuilderRed.setKeyBoadRandom(StringToList((String) DaletouInfo.getDaletouInfo().getLotteryList().get(listTagShow).get(Key.KEY_RED)));
			ballMenuBuilderBlue.setKeyBoadRandom(StringToList((String) DaletouInfo.getDaletouInfo().getLotteryList().get(listTagShow).get(Key.KEY_BLUE)));
			EDebug.o(this, "listTagShow 走着");
		} else {
			btnCancel.setVisibility(View.VISIBLE);
		}

	}

	private ArrayList<Integer> StringToList(String str) {
		ArrayList<Integer> integers = new ArrayList<Integer>();
		String[] strs = str.split(Config.ONESPACE);
		for (int i = 0; i < strs.length; i++) {
			integers.add(Integer.parseInt(strs[i]));
		}
		return integers;
	}

	// 快速添加一注随机选号
	private void randomLotQuickAdd() {

		addSingleRandomToList();

		LayoutParams param = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
		int intTag = DaletouInfo.getDaletouInfo().getLotteryList().size() - 1;

		int redLength = ((String) DaletouInfo.getDaletouInfo().getLotteryList().get(intTag).get(Key.KEY_RED)).length();
		int blueLength = ((String) DaletouInfo.getDaletouInfo().getLotteryList().get(intTag).get(Key.KEY_BLUE)).length();
		View viewListItem = DaletouChooseAct.this.getLayoutInflater().inflate(R.layout.buylist_linear_item, null);
		EDebug.o(DaletouChooseAct.this, "redLength--------------" + redLength);
		EDebug.o(DaletouChooseAct.this, "blueLength------------" + blueLength);
		TextView tvItemRed = (TextView) viewListItem.findViewById(R.id.buylistlinearitem_tv_red);
		tvItemRed.setText(strLengthOption((String) DaletouInfo.getDaletouInfo().getLotteryList().get(intTag).get(Key.KEY_RED), 17));

		TextView tvItemBlue = (TextView) viewListItem.findViewById(R.id.buylistlinearitem_tv_blue);
		tvItemBlue.setText(strLengthOption((String) DaletouInfo.getDaletouInfo().getLotteryList().get(intTag).get(Key.KEY_BLUE), 10));
		TextView tvValue = (TextView) viewListItem.findViewById(R.id.buylistlinearitem_tv_value);
		tvValue.setText(strLengthOption(stringListItemValue(intTag), 7));

		Button btnItemDelete = (Button) viewListItem.findViewById(R.id.buylistlinearitem_btn_delete);
		btnItemDelete.setOnClickListener(DaletouChooseAct.this);
		TextView tvItemStyle = (TextView) viewListItem.findViewById(R.id.buylistlinearitem_tv_touzhustyle);
		if (redLength == 14 && blueLength == 5) {
			tvItemStyle.setText(Language.MSG_DANSHITOUZHU);
		} else {
			tvItemStyle.setText(Language.MSG_FUSHITOUZHU);
		}
		RelativeLayout linearItem = (RelativeLayout) viewListItem.findViewById(R.id.buylistlinearitem_linear_item);
		linearItem.setTag(intTag);
		linearItem.setOnClickListener(listenerListItem);

		viewListItem.setAnimation(AnimationUtils.loadAnimation(DaletouChooseAct.this, R.anim.push_left_in));

		linearListSpace.addView(viewListItem, 0, param);

		betCountAll++;
		moneyAll = betCountAll * eachMoney;
		int money = moneyAll * Integer.parseInt(beishuEnd);
		tvListBetCount.setText(Integer.toString(betCountAll));
		tvListMoney.setText(Integer.toString(money));
	}

	private void addSingleRandomToList() {
		HashMap<String, Object> lotteryListItem = new HashMap<String, Object>();
		lotteryListItem.put(Key.KEY_BLUE, ListIntToString(LotteryUtils.randomNum(2, 12)));
		lotteryListItem.put(Key.KEY_RED, ListIntToString(LotteryUtils.randomNum(5, 35)));
		lotteryListItem.put(Key.KEY_BET_COUNT, 1);
		if (listTagShow == -1) {
			DaletouInfo.getDaletouInfo().getLotteryList().add(lotteryListItem);
		} else {
			DaletouInfo.getDaletouInfo().getLotteryList().add(listTagShow, lotteryListItem);
		}
	}

	// 工具类,待合并
	private String ListToString(List<String> str) {
		StringBuffer sb = new StringBuffer();
		if (str.get(0).length() == 1) {
			sb.append(Config.NUM0).append(str.get(0));
		} else {
			sb.append(str.get(0));
		}
		for (int i = 1; i < str.size(); i++) {
			sb.append(Config.ONESPACE);
			if (str.get(i).length() == 1) {
				sb.append(Config.NUM0).append(str.get(i));
			} else {
				sb.append(str.get(i));
			}
		}
		String result = sb.toString();
		return result;
	}

	private String ListIntToString(List<Integer> list) {
		StringBuffer sb = new StringBuffer();
		if (list.get(0) < 10) {
			sb.append(Config.NUM0).append(Integer.toString(list.get(0)));
		} else {
			sb.append(Integer.toString(list.get(0)));
		}
		for (int i = 1; i < list.size(); i++) {
			sb.append(Config.ONESPACE);
			if (list.get(i) < 10) {
				sb.append(Config.NUM0).append(Integer.toString(list.get(i)));
			} else {
				sb.append(Integer.toString(list.get(i)));
			}
		}

		String result = sb.toString();
		return result;
	}

	private String stringListItemValue(int position) {
		StringBuffer sb = new StringBuffer();
		int bet_count = (Integer) DaletouInfo.getDaletouInfo().getLotteryList().get(position).get(Key.KEY_BET_COUNT);
		int money = bet_count * eachMoney;
		sb.append(Integer.toString(bet_count)).append(Language.POPLOTTERYTIP_ZHU).append(Integer.toString(money)).append(Language.POPLOTTERYTIP_YUAN);

		String result = sb.toString();
		return result;
	}

	private String strLengthOption(String str, int max) {
		if (str.length() < max + 1) {
			return str;
		} else {
			StringBuffer sb = new StringBuffer();
			sb.append(str.substring(0, max - 2)).append(Config.ELLIPSIS);
			String result = sb.toString();
			return result;
		}
	}

	// 将menu键点击事件返回给父activity处理
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {

		if (keyCode == KeyEvent.KEYCODE_MENU || keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
			Activity parent = getParent();
			if (parent != null) {
				parent.onKeyDown(keyCode, event);
				return true;
			}
		}
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			getParent().finish();
			if (UserInfo.getUserInfo().isRebuy()) {
				UserInfo.getUserInfo().setRebuy(false);
				EDebug.o(DaletouChooseAct.this, "is re buy = " + UserInfo.getUserInfo().isRebuy());
				DaletouInfo.getDaletouInfo().getLotteryList().clear();
			}

		}
		return super.onKeyDown(keyCode, event);
	}

	@Override
	public boolean onTrackballEvent(MotionEvent event) {

		Activity parent = getParent();
		if (parent != null) {
			parent.onTrackballEvent(event);
			return true;
		}
		return false;
	}

	@Override
	protected void onResume() {
		// OptionAct.isLoginSucceed = false;
		initShake();
		super.onResume();
		if (showType == 1) {
			getParent().finish();
		} else if (showType == 2) {
			determineSetContentView();
			// setChooseview();
		}

		if (UserInfo.getUserInfo().isBuyingRecharge() && UserInfo.getUserInfo().isRechargeSucceed()) {
			getParent().finish();
			UserInfo.getUserInfo().setBuyingRecharge(false);
			UserInfo.getUserInfo().setRechargeSucceed(false);
		} else if ((!UserInfo.getUserInfo().isBuyingRecharge()) && UserInfo.getUserInfo().isRechargeSucceed()) {
			UserInfo.getUserInfo().setRechargeSucceed(false);
			Intent intentGoon = new Intent();
			if (pageTag == 2) {
				intentGoon.setClass(DaletouChooseAct.this, DaletouChooseHemaiAct.class);
			}
			startActivity(intentGoon);
		} else {
			UserInfo.getUserInfo().setBuyingRecharge(false);
			EDebug.o(DaletouChooseAct.this, "no recharge normal in ");
		}

		if (RegistAct.isRegistSucceed || OptionAct.isLoginSucceed) {
			if (Double.parseDouble(UserInfo.getUserInfo().getUserBalance()) - moneyAll < 0) {
				showZeroMoneyDialog(pageTag);
			}
			RegistAct.isRegistSucceed = false;
			OptionAct.isLoginSucceed = false;
		}
		EDebug.o(DaletouChooseAct.this, "is choose view = " + isChooseView);
		this.registerReceiver(ConnectionChangeReceiver.getConnectionChangeReceiver(), ConnectionChangeReceiver.getIntentFilter());

		if (UserInfo.getUserInfo().isBuyingRecharge()) {
			DaletouChooseAct.this.finish();
			UserInfo.getUserInfo().setBuyingRecharge(false);
			DaletouChooseAct.showType = 1;
		}
		isGetBalance = false;
		threadGetUserBalance();
	}

	@Override
	protected void onPause() {

		if (sensorMgr != null) {
			sensorMgr.unregisterListener(this, SensorManager.SENSOR_ACCELEROMETER);
			sensorMgr = null;
		}

		super.onPause();
		this.unregisterReceiver(ConnectionChangeReceiver.getConnectionChangeReceiver());

	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
	}

	@Override
	public void onAccuracyChanged(int sensor, int accuracy) {

	}

	@Override
	public void onSensorChanged(int sensor, float[] values) {

		if (sensor == SensorManager.SENSOR_ACCELEROMETER) {
			long curTime = System.currentTimeMillis();
			if ((curTime - lastUpdate) > 100) {
				long diffTime = (curTime - lastUpdate);
				lastUpdate = curTime;

				x = values[SensorManager.DATA_X];
				y = values[SensorManager.DATA_Y];
				z = values[SensorManager.DATA_Z];

				float speed = Math.abs(x + y + z - last_x - last_y - last_z) / diffTime * 10000;

				if (speed > SHAKE_THRESHOLD) {
					if (isChooseView && isRandomDialogNotShow) {
						ballMenuBuilderRed.setKeyBoadRandom(LotteryUtils.randomNum(5, 35));
						ballMenuBuilderBlue.setKeyBoadRandom(LotteryUtils.randomNum(2, 12));
						new Vibrate(this).playVibrate(-1);
					}
				}
				last_x = x;
				last_y = y;
				last_z = z;
			}
		}
	}

	private void initShake() {
		sensorMgr = (SensorManager) getSystemService(SENSOR_SERVICE);
		boolean accelSupported = sensorMgr.registerListener(this, SensorManager.SENSOR_ACCELEROMETER, SensorManager.SENSOR_DELAY_GAME);

		if (!accelSupported) {
			// on accelerometer on this device
			sensorMgr.unregisterListener(this, SensorManager.SENSOR_ACCELEROMETER);
		}
	}

	/**
	 * @Title: showZeroMoneyDialog
	 * @Description: 显示余额不足Dialog
	 * @param: pageTag 页面标志位 1为复式代购 2为合买
	 * @return: void 返回类型
	 * @throws
	 */
	private void showZeroMoneyDialog(final int pageTag) {
		final Dialog zeroMoneyDialog = new Dialog(DaletouChooseAct.this, R.style.dialog);
		zeroMoneyDialog.getWindow().setContentView(R.layout.viewerutil_dialog_zeromoney);
		OnClickListener listener = new OnClickListener() {

			@Override
			public void onClick(View v) {

				switch (v.getId()) {
				case R.id.viewerutildialogzeromoney_btn_cancel:
					zeroMoneyDialog.dismiss();
					Intent intentGoon = new Intent();
					if (pageTag == 2) {
						intentGoon.setClass(DaletouChooseAct.this, DaletouChooseHemaiAct.class);
					}
					startActivity(intentGoon);
					break;

				case R.id.viewerutildialogzeromoney_btn_recharge:
					zeroMoneyDialog.dismiss();
					Intent intent = new Intent();
					intent.setClass(DaletouChooseAct.this, RechargeMenuPage.class);
					startActivity(intent);
					UserInfo.getUserInfo().setBuyingRecharge(true);
					break;
				default:
					break;
				}
			}
		};
		Button btnCancel = (Button) zeroMoneyDialog.getWindow().findViewById(R.id.viewerutildialogzeromoney_btn_cancel);
		btnCancel.setText(Language.MSG_CONTINUEBUY);
		btnCancel.setOnClickListener(listener);
		Button btnRecharge = (Button) zeroMoneyDialog.getWindow().findViewById(R.id.viewerutildialogzeromoney_btn_recharge);
		btnRecharge.setOnClickListener(listener);
		((TextView) zeroMoneyDialog.getWindow().findViewById(R.id.viewerutildialogzeromoney_tv_userName)).setText(Language.MSG_YUEBUZUMSG);
		((TextView) zeroMoneyDialog.getWindow().findViewById(R.id.viewerutildialogzeromoney_tv_tipWord)).setVisibility(View.GONE);
		zeroMoneyDialog.show();
	}

	/**
	 * @ClassName: ShowRandomNumDialogAdapter
	 * @Description: 显示选择机选球个数dialog的Adapter
	 * @author: Kael gaojian@500wan.com
	 * @date: 2012-6-21 下午3:11:52
	 * 
	 */
	class ShowRandomNumDialogAdapter extends BaseAdapter {
		private LayoutInflater listInflater;
		private ArrayList<Hashtable<String, Object>> cells;
		private int ballColor;

		public ShowRandomNumDialogAdapter(Context context, ArrayList<Hashtable<String, Object>> cells, int ballColor) {
			this.listInflater = LayoutInflater.from(context);
			this.cells = cells;
			this.ballColor = ballColor;
		}

		@Override
		public int getCount() {
			return cells.size();
		}

		@Override
		public Object getItem(int position) {
			return null;
		}

		@Override
		public long getItemId(int position) {
			return 0;
		}

		@Override
		public View getView(final int position, View convertView, ViewGroup parent) {
			convertView = (Button) listInflater.inflate(R.layout.viewerutil_dialog_randomnum_cell, null);
			final Button button = (Button) convertView.findViewById(R.id.viewerutil_dialog_randomnum_item);
			button.setText(Integer.toString((Integer) cells.get(position).get(Key.KEY_NUM)));
			button.setHeight(65);
			if (ballColor == REDBALL) {
				switch (position) {
				case 0:
					button.setBackgroundResource(R.drawable.btn_random_redballnum_topleft_style);
					break;
				case 5:
					button.setBackgroundResource(R.drawable.btn_random_redballnum_topright_style);
					break;
				case 12:
					button.setBackgroundResource(R.drawable.btn_random_redballnum_leftbottom_style);
					break;
				default:
					button.setBackgroundResource(R.drawable.btn_random_redballnum_mid_style);
					break;
				}

			} else {
				switch (position) {
				case 0:
					button.setBackgroundResource(R.drawable.btn_random_blueballnum_topleft_style);
					break;
				case 5:
					button.setBackgroundResource(R.drawable.btn_random_blueballnum_topright_style);
					break;
				case 6:
					button.setBackgroundResource(R.drawable.btn_random_blueballnum_leftbottom_style);
					break;
				default:
					button.setBackgroundResource(R.drawable.btn_random_blueballnum_mid_style);
					break;
				}

			}

			button.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {

					// 机选蓝球
					if (randomNumTag == RANDOMBLUEBALLTAG) {
						int num = (Integer) cells.get(position).get(Key.KEY_NUM);
						if (randomRedBallNum == 0) {
							randomRedBallNum = 5;
						}
						int moneyNum = 2 * DaletouInfo.getVoteline(randomRedBallNum, 5) * DaletouInfo.getVoteline(num, 2);
						if (moneyNum > Config.MAXIMUM_BET_DALETOU) {
							Toast.makeText(DaletouChooseAct.this, Language.MSG_MAXERWANYUAN, Toast.LENGTH_SHORT).show();
						} else {
							isClicked = true;
							randomBlueBallNum = (Integer) cells.get(position).get(Key.KEY_NUM);
							dialogBlue.dismiss();
						}
						// 机选红球
					} else if (randomNumTag == RANDOMREDBALLTAG) {
						int num = (Integer) cells.get(position).get(Key.KEY_NUM);
						if (randomBlueBallNum == 0) {
							randomBlueBallNum = 2;
						}
						int moneyNum = 2 * DaletouInfo.getVoteline(num, 5) * DaletouInfo.getVoteline(randomBlueBallNum, 2);
						if (moneyNum > Config.MAXIMUM_BET_DALETOU) {
							Toast.makeText(DaletouChooseAct.this, Language.MSG_MAXERWANYUAN, Toast.LENGTH_SHORT).show();
						} else {
							isClicked = true;
							randomRedBallNum = (Integer) cells.get(position).get(Key.KEY_NUM);
							dialogRed.dismiss();
						}

					}

				}
			});
			return convertView;
		}

	}

	/**
	 * @Title: setBlueBallNumArray
	 * @Description: 设定存放机选蓝球个数的ArrayList
	 * @param: @return 设定文件
	 * @return: ArrayList<Hashtable<String,Object>> 返回类型
	 * 
	 */
	private ArrayList<Hashtable<String, Object>> setBlueBallNumArray() {
		ArrayList<Hashtable<String, Object>> blueBallNumArray = new ArrayList<Hashtable<String, Object>>();
		for (int i = 2; i < 13; i++) {
			Hashtable<String, Object> blueBallNumHash = new Hashtable<String, Object>();
			blueBallNumHash.put(Key.KEY_NUM, i);
			blueBallNumArray.add(blueBallNumHash);
		}
		return blueBallNumArray;
	}

	/**
	 * @Title: setRedBallNumArray
	 * @Description: 设定存放机选红球个数的ArrayList
	 * @param: @return 设定文件
	 * @return: ArrayList<Hashtable<String,Object>> 返回类型
	 * 
	 */
	private ArrayList<Hashtable<String, Object>> setRedBallNumArray() {
		ArrayList<Hashtable<String, Object>> redBallNumArray = new ArrayList<Hashtable<String, Object>>();
		for (int i = 5; i < 19; i++) {
			Hashtable<String, Object> redBallNumHash = new Hashtable<String, Object>();
			redBallNumHash.put(Key.KEY_NUM, i);
			redBallNumArray.add(redBallNumHash);
		}
		return redBallNumArray;
	}

	/**
	 * @Title: setWheelContent
	 * @Description: 设置存放追号期数 倍数的ArrayList
	 * @param: @param num
	 * @param: @return 设定文件
	 * @return: ArrayList<String> 返回类型
	 * 
	 */
	private ArrayList<String> setWheelContent(int num) {
		ArrayList<String> array = new ArrayList<String>();
		array.add(Config.NUM0);
		for (int i = 1; i < num + 1; i++) {
			String s = Integer.toString(i);
			array.add(s);
		}
		return array;
	}

	/**
	 * @Title: initDate
	 * @Description: 初始化数据
	 * @param: 设定文件
	 * @return: void 返回类型
	 * 
	 */
	private void initDate() {
		eachMoney = 2;
		arrBlueBallNum = new ArrayList<Hashtable<String, Object>>();
		arrRedBallNum = new ArrayList<Hashtable<String, Object>>();
		arrBlueBallNum = setBlueBallNumArray();
		arrRedBallNum = setRedBallNumArray();
		beishuNum = new ArrayList<String>();
		zhuihaoNum = new ArrayList<String>();
		beishuNum = setWheelContent(50);
		zhuihaoNum = setWheelContent(30);

	}

	/**
	 * @Title: showBeitouZhuihaoDialog
	 * @Description: 显示设置倍投 追号的Dialog
	 * @param: 设定文件
	 * @return: void 返回类型
	 * 
	 */
	private void showBeitouZhuihaoDialog() {
		beiTouZhuihaoDialog = new Dialog(DaletouChooseAct.this, R.style.dialog);
		beiTouZhuihaoDialog.getWindow().setContentView(R.layout.dialog_beitou_zhuihao_setting);

		btnDialogFinish = (Button) beiTouZhuihaoDialog.findViewById(R.id.dialog_beitou_zhuihao_btn_submit);
		btnDialogFinish.setOnClickListener(this);

		btnDialogCancel = (Button) beiTouZhuihaoDialog.findViewById(R.id.dialog_beitou_zhuihao_btn_cancle);
		btnDialogCancel.setOnClickListener(this);

		linear_zhuijiatouzhu = (LinearLayout) beiTouZhuihaoDialog.findViewById(R.id.dialog_ll_zhuijiatouzhu);
		linear_zhuijiatouzhu.setVisibility(View.VISIBLE);

		cbDialog_zhuijiatouzhu = (CheckBox) beiTouZhuihaoDialog.findViewById(R.id.dialog_cb_zhuijiatouzhu);
		cbDialog_zhuijiatouzhu.setOnCheckedChangeListener(new OnCheckedChangeListener() {

			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				if (isChecked) {
					isZhuiJiaTouZhu = true;
					eachMoney = 3;
					moneyAll = betCountAll * eachMoney;
				} else {
					isZhuiJiaTouZhu = false;
					eachMoney = 2;
					moneyAll = betCountAll * eachMoney;
				}

			}
		});

		cbDialogStop = (CheckBox) beiTouZhuihaoDialog.findViewById(R.id.dialog_cb_stop);
		cbDialogStop.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				if (isChecked) {
					isStopZhuihao = true;
				} else {
					isStopZhuihao = false;
				}

			}
		});

		beishuWheel = (WheelView) beiTouZhuihaoDialog.findViewById(R.id.dialog_beitou_choose_wheel);
		beishuWheel.setAdapter(new NumericWheelAdapter(beishuNum));
		beishuWheel.setCurrentItem(Integer.parseInt(beishuEnd) - 1);
		beishuWheel.addChangingListener(changedListener);
		beishuWheel.addScrollingListener(scrolledListener);
		beishuWheel.setCyclic(true);
		beishuWheel.setVisibleItems(5);
		beishuWheel.setInterpolator(new AnticipateOvershootInterpolator());

		zhuihaoWheel = (WheelView) beiTouZhuihaoDialog.findViewById(R.id.dialog_zhuihao_choose_wheel);
		zhuihaoWheel.setAdapter(new NumericWheelAdapter(zhuihaoNum));
		zhuihaoWheel.setCurrentItem(Integer.parseInt(zhuihaoEnd) - 1);
		zhuihaoWheel.addChangingListener(changedListener);
		zhuihaoWheel.addScrollingListener(scrolledListener);
		zhuihaoWheel.setCyclic(true);
		zhuihaoWheel.setVisibleItems(5);
		zhuihaoWheel.setInterpolator(new AnticipateOvershootInterpolator());

		WindowManager.LayoutParams windowLp = beiTouZhuihaoDialog.getWindow().getAttributes();

		int[] location = new int[2];
		btnListClean.getLocationOnScreen(location);
		int totalTopHeight = location[1];
		EDebug.o(this, "total top height = " + totalTopHeight);
		int btnHeight = btnListClean.getHeight();
		EDebug.o(this, "btn Height  = " + btnHeight);
		int dialogHeight = windowLp.height;
		EDebug.o(this, "dialog Height = " + dialogHeight);
		int finalY = totalTopHeight + btnHeight - dialogHeight;
		EDebug.o(this, "finalY = " + finalY);

		windowLp.y = finalY;

		beiTouZhuihaoDialog.onWindowAttributesChanged(windowLp);

		beiTouZhuihaoDialog.show();
	}

	private OnWheelChangedListener changedListener = new OnWheelChangedListener() {

		@Override
		public void onChanged(WheelView wheel, int oldValue, int newValue) {
			if (!wheelScrolled) {
				updateStatus();
			}
		}
	};
	private OnWheelScrollListener scrolledListener = new OnWheelScrollListener() {

		@Override
		public void onScrollingStarted(WheelView wheel) {
			wheelScrolled = true;
		}

		@Override
		public void onScrollingFinished(WheelView wheel) {
			wheelScrolled = false;
			updateStatus();
		}

	};

	/**
	 * @Title: updateStatus
	 * @Description: 获取滚轮滑动到位置的数值
	 * @param: 设定文件
	 * @return: void 返回类型
	 * 
	 */
	private void updateStatus() {
		beishuCurrent = beishuNum.get(beishuWheel.getCurrentItem() + 1);
		zhuihaoCurrent = zhuihaoNum.get(zhuihaoWheel.getCurrentItem() + 1);
		EDebug.o(DaletouChooseAct.this, "倍数" + beishuCurrent);
		EDebug.o(DaletouChooseAct.this, "追号" + zhuihaoCurrent);
	}

	/**
	 * @Title: showSubmitOrderDialog
	 * @Description: 显示提交订单的Dialog
	 * @param: 设定文件
	 * @return: void 返回类型
	 * 
	 */
	private void showSubmitOrderDialog(String msg, String submit) {
		submitOrderDialog = new Dialog(DaletouChooseAct.this, R.style.dialog);
		submitOrderDialog.getWindow().setContentView(R.layout.dialog_quit);
		TextView tvDialogMsg = (TextView) submitOrderDialog.getWindow().findViewById(R.id.dialogquit_tv_msg);
		tvDialogMsg.setText(msg);
		btnSubmitOrder = (Button) submitOrderDialog.getWindow().findViewById(R.id.dialogquit_btn_submit);
		btnSubmitOrder.setText(submit);
		btnSubmitOrder.setOnClickListener(this);
		btnCancelOrder = (Button) submitOrderDialog.getWindow().findViewById(R.id.dialogquit_btn_cancel);
		btnCancelOrder.setOnClickListener(this);
	}

	/**
	 * @Title: initHandler
	 * @Description: 初始化Handler
	 * @param: 设定文件
	 * @return: void 返回类型
	 * 
	 */
	private void initHandler() {
		handlerNormalBuy = new Handler() {
			@Override
			public void handleMessage(Message msg) {
				switch (msg.what) {
				case NORMALBUY_SUCCEED:
					buySucceed();
					DaletouInfo.getDaletouInfo().getLotteryList().clear();
					break;

				case NORMALBUY_FAIL:
					if (daletouNormalBuyCommunicater.getState() == 0) {
						ViewerUtil.showTipDialog(DaletouChooseAct.this, daletouNormalBuyCommunicater.getErrorMSG() + Config.COMMA + Language.POPLOTTERYTIP_LOOKOVERRECORD, false);
					} else if (daletouNormalBuyCommunicater.getState() == 105) {
						popBalanceNotEnoughAlert();
					} else {
						// ViewerUtil.showTipDialog(DaletouChooseAct.this, daletouNormalBuyCommunicater.getErrorMSG(), false);
						Toast.makeText(DaletouChooseAct.this, daletouNormalBuyCommunicater.getErrorMSG(), 0).show();
					}
					break;

				case Config.CONNECTION_FAIL:
					if (daletouNormalBuyCommunicater.getState() == 0) {
						// ViewerUtil.showTipDialog(DaletouChooseAct.this, Language.POPLOTTERYTIP_LOOKOVERRECORD, false);
						Toast.makeText(DaletouChooseAct.this, Language.POPLOTTERYTIP_LOOKOVERRECORD, 0).show();
					}
					// ViewerUtil.showTipDialog(ShuangseqiuChooseNormalBuyAct.this, Language.STR_CONNECTIONFAIL, false);
					break;

				case GETBALANCE_SUCCEED:
					userCommunicater.updataUserInfo();
					isGetBalance = true;
					break;

				case GETBALANCE_FAIL:
					isGetBalance = true;
					break;

				case GET_EXPECT_LIST_SUCCEED:

					threadNormalBuy(expectCommuniacter.getTrackExceptionList());

					break;

				case GET_EXPECT_LIST_FAILED:

					// ViewerUtil.showTipDialog(DaletouChooseAct.this, Language.MSG_GETEXPECTLISTFAFAILED, false);
					Toast.makeText(DaletouChooseAct.this, Language.MSG_GETEXPECTLISTFAFAILED, 0).show();

					break;

				case GET_LOTTERY_NUM_SUCCEED:
					lotteryNumInfo = currentLotteryNumCommunicater.getCurrentLotteryNum().get(0);
					String lastopencode = lotteryNumInfo.getLastopencode();
					if (lastopencode != null && !lastopencode.equals(Config.NULLMARK)) {
						String opencode[] = lastopencode.split("\\|");
						redcode = opencode[0].replace(Config.COMMA, Config.ONESPACE);
						bluecode = opencode[1].replace(Config.COMMA, Config.ONESPACE);
						llLastLotteryNumProgress.setVisibility(View.GONE);
						llLastLotteryNum.setVisibility(View.VISIBLE);
						tvLastLotteryNumRed.setText(redcode);
						tvLastLotteryNumBlue.setText(bluecode);
					} else {
						llLastLotteryNumProgress.setVisibility(View.GONE);
						llLastLotteryNumShibai.setVisibility(View.VISIBLE);
					}
					break;

				case GET_LOTTERY_NUM_FAILED:
					llLastLotteryNumShibai.setVisibility(View.VISIBLE);
					break;

				case DO_REFRESH:
					determineSetContentView();
					break;

				default:
					break;
				}
				progressdialogNormalbuy.dismiss();
			}
		};

	}

	/**
	 * @Title: threadGetExpectList
	 * @Description: 获取期号列表
	 * @param: @param startExpect
	 * @param: @param num 设定文件
	 * @return: void 返回类型
	 * 
	 */
	private void threadGetExpectList(final String startExpect, final String num) {

		new Thread() {

			@Override
			public void run() {

				super.run();
				Message msg = new Message();
				try {
					if (expectCommuniacter == null) {
						expectCommuniacter = new DaletouTraceExpectCommunicater();
					}
					boolean isGetSucceed = expectCommuniacter.isGetExpectSucceed(startExpect, num);
					if (isGetSucceed) {
						msg = handlerNormalBuy.obtainMessage(GET_EXPECT_LIST_SUCCEED, null);
					} else {
						msg = handlerNormalBuy.obtainMessage(GET_EXPECT_LIST_FAILED, null);
					}
					handlerNormalBuy.sendMessage(msg);
				} catch (Exception e) {

					msg = handlerNormalBuy.obtainMessage(Config.CONNECTION_FAIL, null);
					handlerNormalBuy.sendMessage(msg);
				}
			}
		}.start();

	}

	/**
	 * @Title: threadNormalBuy
	 * @Description: 复式购买
	 * @param: @param expectList 设定文件
	 * @return: void 返回类型
	 * 
	 */
	private void threadNormalBuy(final String expectList) {

		new Thread() {
			@Override
			public void run() {
				super.run();
				try {
					if (daletouNormalBuyCommunicater == null) {
						daletouNormalBuyCommunicater = new DaletouNormalBuyCommunicater();
					}
					int buyzhuihao = Integer.parseInt(zhuihaoEnd);
					int buybeishu = Integer.parseInt(beishuEnd);
					int buymoney = betCountAll * buybeishu * buyzhuihao * eachMoney;
					boolean isBuySucceed = daletouNormalBuyCommunicater.isBuySucceed(betCountAll, buybeishu, buyzhuihao, buymoney, isStopZhuihao, isZhuiJiaTouZhu, expectList);
					if (isBuySucceed) {
						Message msg = handlerNormalBuy.obtainMessage(NORMALBUY_SUCCEED, null);
						handlerNormalBuy.sendMessage(msg);
					} else {
						Message msg = handlerNormalBuy.obtainMessage(NORMALBUY_FAIL, null);
						handlerNormalBuy.sendMessage(msg);
					}
				} catch (Exception e) {

					Message msg = handlerNormalBuy.obtainMessage(Config.CONNECTION_FAIL, null);
					handlerNormalBuy.sendMessage(msg);
				}
			}
		}.start();
	}

	/**
	 * @Title: buySucceed
	 * @Description:购买成功
	 * @param: 设定文件
	 * @return: void 返回类型
	 * 
	 */
	private void buySucceed() {
		dialogBuySucceed = new Dialog(this, R.style.dialog);
		dialogBuySucceed.setContentView(R.layout.viewerutil_dialog_showbuysucceed);
		((TextView) dialogBuySucceed.getWindow().findViewById(R.id.viewerutildialogshowbuysucceed_tv_msg)).setText(Language.MSG_BUYSUCCEED);
		((TextView) dialogBuySucceed.getWindow().findViewById(R.id.viewerutildialogshowbuysucceed_tv_term)).setText("购买超级大乐透" + DaletouInfo.getDaletouInfo().getTermNum() + Language.POPLOTTERYTIP_QI
				+ betCountAll + Language.POPLOTTERYTIP_ZHU);
		((TextView) dialogBuySucceed.getWindow().findViewById(R.id.viewerutildialogshowbuysucceed_tv_count)).setText(Language.MSG_ZHUIHAO + zhuihaoEnd + Language.POPLOTTERYTIP_QI);
		((TextView) dialogBuySucceed.getWindow().findViewById(R.id.viewerutildialogshowbuysucceed_tv_cost)).setText(Language.MSG_RESULT_HEMAI_XIAOFEI + Language.POPLOTTERYTIP_RMB
				+ Integer.toString(betCountAll * Integer.parseInt(beishuEnd) * eachMoney));
		((TextView) dialogBuySucceed.getWindow().findViewById(R.id.viewerutildialogshowbuysucceed_tv_balance)).setText(Language.MSG_RESULT_HEMAI_SHENGYUJINE + Language.POPLOTTERYTIP_RMB
				+ UserInfo.getUserInfo().getUserBalance());
		dialogBuySucceed.show();
		OnClickListener dialogSucceedListener = new View.OnClickListener() {

			@Override
			public void onClick(View v) {

				switch (v.getId()) {
				case R.id.viewerutildialogshowbuysucceed_btn_back:
					dialogBuySucceed.dismiss();

					if (UserInfo.getUserInfo().isRebuy()) {
						if (DaletouChooseAct.this.getParent() != null) {
							DaletouChooseAct.this.getParent().finish();
							UserInfo.getUserInfo().setRebuy(false);
							return;
						}
					}
					DaletouChooseAct.showType = 2;
					UserInfo.getUserInfo().setRebuy(false);
					DaletouInfo.getDaletouInfo().getLotteryList().clear();
					beishuEnd = Config.NUM1;
					zhuihaoEnd = Config.NUM1;
					tvListBeiShu.setText(beishuEnd);
					tvListZhuiHao.setText(zhuihaoEnd);
					setChooseview();
					break;

				case R.id.viewerutildialogshowbuysucceed_btn_toHall:
					dialogBuySucceed.dismiss();
					DaletouChooseAct.this.getParent().finish();
					DaletouChooseAct.showType = 1;
					break;

				default:
					break;
				}

			}
		};
		Button btnBc = (Button) dialogBuySucceed.getWindow().findViewById(R.id.viewerutildialogshowbuysucceed_btn_back);
		btnBc.setOnClickListener(dialogSucceedListener);
		if (UserInfo.getUserInfo().isRebuy()) {
			btnBc.setText("返回详情");
		}
		((Button) dialogBuySucceed.getWindow().findViewById(R.id.viewerutildialogshowbuysucceed_btn_toHall)).setOnClickListener(dialogSucceedListener);

	}

	/**
	 * @Title: popBalanceNotEnoughAlert
	 * @Description: 余额不足Dialog
	 * @param: 设定文件
	 * @return: void 返回类型
	 * 
	 */
	private void popBalanceNotEnoughAlert() {
		if (dialogBalanceNotEnough == null) {
			dialogBalanceNotEnough = new Dialog(this, R.style.dialog);
		}

		if (moneyNotEnoughListener == null) {
			moneyNotEnoughListener = new OnClickListener() {

				@Override
				public void onClick(View v) {
					switch (v.getId()) {
					case R.id.shiyixuanwu_alert_money_not_enough_btn_cancel:
						break;

					case R.id.shiyixuanwu_alert_money_not_enough_btn_recharge:
						UserInfo.getUserInfo().setBuyingRecharge(true);

						DaletouChooseAct.this.startActivity(new Intent().setClass(DaletouChooseAct.this, RechargeMenuPage.class));

						break;
					}

					dialogBalanceNotEnough.dismiss();
				}
			};
		}

		View view = this.getLayoutInflater().inflate(R.layout.shiyixuanwu_alert_money_not_enough, null);

		((Button) view.findViewById(R.id.shiyixuanwu_alert_money_not_enough_btn_cancel)).setOnClickListener(moneyNotEnoughListener);
		((Button) view.findViewById(R.id.shiyixuanwu_alert_money_not_enough_btn_recharge)).setOnClickListener(moneyNotEnoughListener);

		dialogBalanceNotEnough.setContentView(view);
		dialogBalanceNotEnough.show();
	}

	/**
	 * @Title: threadGetUserBalance
	 * @Description: 获取用户余额
	 * @param: 设定文件
	 * @return: void 返回类型
	 * 
	 */
	private void threadGetUserBalance() {
		new Thread() {
			@Override
			public void run() {
				super.run();
				try {
					if (userCommunicater == null) {
						userCommunicater = new UserCommunicater();
					}
					Boolean b = userCommunicater.isLoginSucceed(UserInfo.getUserInfo().getUserName(), UserInfo.getUserInfo().getUserPwd());
					if (b) {
						Message msg = handlerNormalBuy.obtainMessage(GETBALANCE_SUCCEED, null);
						handlerNormalBuy.sendMessage(msg);
					} else {
						Message msg = handlerNormalBuy.obtainMessage(GETBALANCE_FAIL, null);
						handlerNormalBuy.sendMessage(msg);
					}
				} catch (Exception e) {
					Message msg = handlerNormalBuy.obtainMessage(GETBALANCE_FAIL, null);
					handlerNormalBuy.sendMessage(msg);

				}
			}
		}.start();
	}

	/**
	 * @Title: threadGetCurrentLotteryNum
	 * @Description: 获取当前开奖号码
	 * @param: @param lotid 设定文件
	 * @return: void 返回类型
	 * 
	 */
	private void threadGetCurrentLotteryNum(final String lotid) {
		new Thread() {

			@Override
			public void run() {
				super.run();
				Message msg;
				try {
					if (currentLotteryNumCommunicater == null) {
						currentLotteryNumCommunicater = new CurrentLotteryNumCommunicater();
					}
					boolean isGetLotteryNumSucceed = currentLotteryNumCommunicater.isGetCurrentLotteryNumSucceed(lotid);
					if (isGetLotteryNumSucceed) {
						msg = handlerNormalBuy.obtainMessage(GET_LOTTERY_NUM_SUCCEED, null);
					} else {
						msg = handlerNormalBuy.obtainMessage(GET_LOTTERY_NUM_FAILED, null);
					}
					handlerNormalBuy.sendMessage(msg);
				} catch (Exception e) {
					msg = handlerNormalBuy.obtainMessage(Config.CONNECTION_FAIL, null);
					handlerNormalBuy.sendMessage(msg);
				}

			}

		}.start();
	}

	/**
	 * @Title: topHeight
	 * @Description: 计算手机屏幕上边提示栏的高度
	 * @param: @param context
	 * @param: @return 设定文件
	 * @return: int 返回类型
	 * @throws
	 */
	private int getTopHeight() {
		int topBarHeight = 0;
		Rect rect = new Rect();
		getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
		topBarHeight = rect.top;
		EDebug.o("rect.height()" + rect.height() + "rect.top" + rect.top);
		return topBarHeight;
	}
}
